package com.sky.controller.admin;


import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController("AdminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "客户端店铺状态")
public class ShopController {

    public static final String KEY = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;


    @PutMapping("/{status}")
    @ApiOperation("设置店铺状态")
    public Result status(@PathVariable Integer status) {
        ValueOperations value = redisTemplate.opsForValue();
        value.set(KEY, status);
        return Result.success();
    }


    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result getStatus() {
        ValueOperations value = redisTemplate.opsForValue();
        Integer status = (Integer) value.get(KEY);
        return Result.success(status);
    }

}
